<?php

namespace App\System\Base\Repositories;

use App\System\Base\Helpers\Traits\SinglePattern;
use App\System\Base\Model\BaseSmsCode;

class BaseSmsCodeRepository extends Repository
{
    use SinglePattern;


    public function getSmsCode($mobile,$session_id,$ip)
    {

        $res = BaseSmsCode::whereBetween('created_at',1,2)
            ->where('mobile',$mobile)
            ->where('session_id',$session_id)
            ->where('ip',$ip)
            ->where('status',2)
            ->get()->count();

        return $res;
    }

    /**
     * 通过ID查询验证码记录,并且验证是否验证过
     * @param $id
     * @param $type
     * @return bool
     */
    public function getOneById($id,$type)
    {
        $sms_info = BaseSmsCode::where("id",$id)->where("type",$type)->first();
        if(!$sms_info || $sms_info->status != 1)
        {
            return ['s'=>'10000','d'=>"操作失败，未验证验证码"];
        }
        return ['s'=>'0','d'=>'操作成功'];
    }

}